package com.android.equipment.adapter

import android.annotation.SuppressLint
import android.graphics.Color
import android.view.View
import android.widget.TextView
import com.android.equipment.R
import com.android.equipment.config.Constant
import com.android.equipment.dao.Work
import com.android.equipment.utils.ToastUtil
import com.blankj.utilcode.util.LogUtils
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder

class WorkAdapter(layoutResId: Int) : BaseQuickAdapter<Work, BaseViewHolder>(layoutResId) {
    @SuppressLint("SetTextI18n")
    override fun convert(holder: BaseViewHolder, item: Work) {
        holder.setText(R.id.tv_work_name, item.name)
        holder.setText(R.id.tv_create_time, "创建时间：${item.addTime}")

        val tvPeopleNum = holder.getView<TextView>(R.id.tv_people_num)
        if (item.peopleNum > 0) {
            tvPeopleNum.visibility = View.VISIBLE
            tvPeopleNum.text = "参与人数：${item.peopleNum}人"
        } else {
            tvPeopleNum.visibility = View.GONE
        }

        val tvBeginTime = holder.getView<TextView>(R.id.tv_begin_time)
        if (null != item.beginTime) {
            tvBeginTime.visibility = View.VISIBLE
            tvBeginTime.text = "开始时间：${item.beginTime}"
        } else {
            tvBeginTime.visibility = View.GONE
        }


        val tvEndTime = holder.getView<TextView>(R.id.tv_end_time)
        if (null != item.endTime) {
            tvEndTime.visibility = View.VISIBLE
            tvEndTime.text = "结束时间：${item.endTime}"
        } else {
            tvEndTime.visibility = View.GONE
        }

        holder.setText(R.id.tv_status, Constant.workList[item.status])
        when (item.status) {
            0 -> {
                holder.setTextColor(R.id.tv_status, Color.parseColor("#FF7300"))
            }

            1 -> {
                holder.setTextColor(R.id.tv_status, Color.parseColor("#4CE5B1"))
            }

            2 -> {
                holder.setTextColor(R.id.tv_status, Color.parseColor("#798492"))
            }
        }
    }
}